import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'
import Home from '../views/Home.vue'
import User from '../views/system/User.vue'
import Login from '@/views/Login.vue'
import Index from '@/views/Index.vue'
import TopicType from '@/views/topic/TopicType'
import TopicJava from '@/views/topic/TopicJava'
import TopicAdd from '@/views/topic/TopicAdd'
import GptAi from '@/views/GptAi'
import TopicAudit from '@/views/topic/TopicAudit'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    component: HomeView,
    redirect: "/home",
    children: [
      { path: 'user', name: 'User', meta: { title: '用户管理' }, component: User },
      { path: 'home', name: 'Home', meta: { title: '主页' }, component: Home },
      { path: 'topic_type', name: 'TopicType', meta: { title: '题库类型' }, component: TopicType },
      { path: 'topic_java', name: 'TopicJava', meta: { title: 'Java题库' }, component: TopicJava },
      { path: 'topic_add', name: 'TopicAdd', meta: { title: '添加题目' }, component: TopicAdd },
      { path: 'topic_audit', name: 'TopicAudit', meta: { title: '题目审核' }, component: TopicAudit },
    ]
  },
  { path: '/index', name: 'index', meta: { title: '首页' }, component: Index },
  { path: '/gpt', name: 'GptAi', meta: { title: '女仆' }, component: GptAi },
  {
    path: '/login',
    name: 'login',
    component: Login,
  }

]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
router.beforeEach((to, from, next) => {
  if (to.path == '/login') {
    //保存当前路由
    localStorage.setItem("preRoute", router.currentRoute.fullPath)
  }
  next()
})

export default router
